let perm = [
    'main:start',
    'main:stop',
    'main:reset',
    'main:open:cylinder',
    'main:pass:car',
    'main:untightening',
    'main:repair',
    'user:view',
    'user:add',
    'user:delete',
    'user:assign',
    'recipe:view',
    'recipe:add',
    'recipe:edit',
    'recipe:view:pn',
    'recipe:bn',
    'recipe:delete',
    'prod:view',
    'prod:upload:upper',
    'prod:upload:front',
    'prod:pass',
    'prod:detail',
    'setting:view',
    'setting:mes',
    'setting:agv',
    'setting:bn',
    'setting:line',
    'setting:other',
    'derive:view',
    'derive:edit',
    'log:edit',
    'log:view',
];

/**
 * 获取权限列表
 * @constructor
 */
function GetPermissionListApi (user,callback) {
    if (user.Id === 1) {
        user.permission = perm;
        callback(user);
    } else {
        window.PermissionApi.getPermissionList(user.id).then(r => {
            console.log(r,33333);
            let _perm = [];
            if (!IsEmpty(r.Data)) {
                for (let datum of r.Data) {
                    _perm.push(datum.Code);
                }
            }
            user.permission = _perm;
            callback(user);
        });
    }
}

/**
 * 添加权限
 * @param user
 * @constructor
 */
function AddPermissionApi (permission) {
    return window.PermissionApi.addPermission(JSON.stringify(permission));
}

/**
 * 删除权限
 * @param id
 * @constructor
 */
function DeletePermissionApi (userId, code) {
    return window.PermissionApi.deletePermission(userId, code);
}